<?php
   	include_once "../funciones.php";
        include_once "../validacionPHP/validacion.php";
    validar($_REQUEST);

    $con=conectar();
	$fallo=false;
   
   try {
		if (".$_REQUEST[TIPO]." !=0){	
		
		
			$con->beginTransaction();
			$OID=getOIDNuevo('MATERIALES', 'OID_MAT');
			if (".$_REQUEST[TIPO]." == 1){
		 
				$sql1="INSERT INTO MATERIALES VALUES  (".$OID.",".$_REQUEST[CANTIDAD].", ".$_REQUEST[CANTIDAD].")";
				$stmt = $con->prepare($sql1);
				$stmt->execute();
				$stmt = $con->prepare("commit");
				$stmt->execute();
			
				$sql="INSERT INTO MATERIALES_DEPORTIVOS VALUES (".$OID.",'".$_REQUEST[MATERIAL]."')";
				$stmt = $con->prepare($sql);
				$stmt->execute();
				$stmt = $con->prepare("commit");
				$stmt->execute();			
			 
			 }else {
				
				$sql1="INSERT INTO MATERIALES VALUES  (".$OID.",".$_REQUEST[CANTIDAD].", ".$_REQUEST[CANTIDAD].")";
				$stmt = $con->prepare($sql1);
				$stmt->execute();
				$stmt = $con->prepare("commit");
				$stmt->execute();
				
				$sql="INSERT INTO MATERIALES_TEXTILES VALUES (".$OID.",".$_REQUEST[TALLA].", '".$_REQUEST[MATERIAL]."')";
				$stmt = $con->prepare($sql);
				$stmt->execute();
				$stmt = $con->prepare("commit");
				$stmt->execute();
			
				}
		}else{
			echo "error: ".$e->GetMessage();
            $con->rollBack();
            header( 'Location: insertarMateriales.php?exito=2');
   	        $fallo=true;
		}
		
	}catch(PDOException $e ) {
			echo "error: ".$e->GetMessage();
            $con->rollBack();
            header( 'Location: insertarMateriales.php?exito=2');
   	        $fallo=true;

	}
    if($fallo==false)
        header( 'Location: insertarMateriales.php?exito=1');


   ?>